package com.nt.thah.enums;

/**
 * API 统一返回状态码
 */
public enum ResultCode {

    SUCCESS(200, "成功"),
    PARAM_IS_INVALID(10001, "请求的数据格式不符"),

    /* 用户错误：20001-29999*/
    USER_NOT_LOGGED_IN(20001, "用户未登录"),
    USER_LOGIN_ERROR(20002, "账号不存在或密码错误"),
    USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
    USER_NOT_EXIST(20004, "该用户不存在"),
    USER_HAS_EXISTED(20005, "该用户已存在"),
    USER_PHONE_EXISTED(20006, "该手机号已注册"),
    USER_NAME_CARD_NOT_MATCH(20007, "身份证号和姓名不匹配"),
    USER_ID_CARD_EXISTED(20008, "身份证号已存在"),
    USER_LOGIN_TIMEOUT(20009, "登录状态失效，未获取到登录状态"),
    USER_NOT_REAL(20010, "用户未实名"),

    /* 业务错误：30001-39999 */
    SPECIFIED_QUESTIONED_USER_NOT_EXIST(30001, "某业务出现问题"),

    /* 系统错误：40001-49999 */
    SYSTEM_INNER_ERROR(40001, "系统繁忙，请稍后重试"),
    SYSTEM_IN_MAINTENANCE(40002, "系统维护中"),
    SYSTEM_IS_TOO_BUSY(40003, "操作频繁，请稍候再试"),

    /* 数据错误：50001-599999 */
    RESULT_DATA_NONE(50001, "未查询到相关信息"),
    DATA_IS_WRONG(50002, "数据有误"),
    DATA_ALREADY_EXISTED(50003, "数据已存在"),

    /* 接口错误：60001-69999 */
    INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"),
    INTERFACE_OUTTER_INVOKE_ERROR(60002, "外部系统接口调用异常"),
    INTERFACE_FORBID_VISIT(60003, "该接口禁止访问"),
    INTERFACE_ADDRESS_INVALID(60004, "接口地址无效"),
    INTERFACE_REQUEST_TIMEOUT(60005, "接口请求超时"),
    INTERFACE_EXCEED_LOAD(60006, "接口负载过高"),
    GET_SMS_CODE_ERROR(60007, "获取短信验证码失败,请稍后再试"),
    COUNT_SMS_CODE_LIMIT_ERROR(60008, "获取短信验证码次数过多,请稍后再试"),
    VALIDATE_SMS_CODE_ERROR(60009, "验证码错误或者为空"),
    USER_NON_SUBSCRIBE(60010, "用户未关注公众号"),
    GET_WX_USER_ERROR(60011, "获取微信授权信息失败"),
    LIMIT_NUM_ERROR(60012, "超出数量限制"),
    REPEAT_SETTLE(60016, "该手机号之前结算过该产品，请核查清楚"),
    WITHDRAW_ERROR(60017, "提现失败，请检查"),
    BANKCARD_ERROR(60026, "签约失败，请检查"),
    ;


    private Integer code;

    private String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public static String getMessage(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }

}